(function () {
    'use strict';

    class DefineConfig {
    }
    DefineConfig.isLog = true;
    DefineConfig.globalConfig = "GlobalConfig.config";

    class Debug {
        static log(...data) {
            if (DefineConfig.isLog) {
                console.log(data);
            }
        }
        static warn(...data) {
            if (DefineConfig.isLog) {
                console.warn(data);
            }
        }
        static error(...data) {
            if (DefineConfig.isLog) {
                console.error(data);
            }
        }
    }

    class CameraCtrBase extends Laya.Script {
        onStart() {
            this._scene = this.owner.parent;
            this.cameraTrans = this.owner.transform;
        }
        onEnable() {
            Debug.log("启用相机控制器->" + typeof (this).toString());
        }
        onDisable() {
            Debug.log("禁用相机控制器->" + typeof (this).toString());
        }
    }

    class CameraMoveScript extends CameraCtrBase {
        constructor() {
            super();
            this._tempVector3 = new Laya.Vector3();
            this.yawPitchRoll = new Laya.Vector3();
            this.resultRotation = new Laya.Quaternion();
            this.tempRotationZ = new Laya.Quaternion();
            this.tempRotationX = new Laya.Quaternion();
            this.tempRotationY = new Laya.Quaternion();
            this.rotaionSpeed = 0.00006;
        }
        onAwake() {
            Laya.stage.on(Laya.Event.RIGHT_MOUSE_DOWN, this, this.mouseDown);
            Laya.stage.on(Laya.Event.RIGHT_MOUSE_UP, this, this.mouseUp);
        }
        onEnable() {
            super.onEnable();
        }
        onDisable() {
            super.onDisable();
        }
        _updateRotation() {
            if (Math.abs(this.yawPitchRoll.y) < 1.50) {
                Laya.Quaternion.createFromYawPitchRoll(this.yawPitchRoll.x, this.yawPitchRoll.y, this.yawPitchRoll.z, this.tempRotationZ);
                this.tempRotationZ.cloneTo(this.cameraTrans.localRotation);
                this.cameraTrans.localRotation = this.cameraTrans.localRotation;
            }
        }
        onUpdate() {
            var elapsedTime = Laya.timer.delta;
            if (!isNaN(this.lastMouseX) && !isNaN(this.lastMouseY) && this.isMouseDown) {
                var offsetX = Laya.stage.mouseX - this.lastMouseX;
                var offsetY = Laya.stage.mouseY - this.lastMouseY;
                var yprElem = this.yawPitchRoll;
                yprElem.x -= offsetX * this.rotaionSpeed * elapsedTime;
                yprElem.y -= offsetY * this.rotaionSpeed * elapsedTime;
                this._updateRotation();
            }
            this.lastMouseX = Laya.stage.mouseX;
            this.lastMouseY = Laya.stage.mouseY;
        }
        onDestroy() {
            Laya.stage.off(Laya.Event.RIGHT_MOUSE_DOWN, this, this.mouseDown);
            Laya.stage.off(Laya.Event.RIGHT_MOUSE_UP, this, this.mouseUp);
        }
        mouseDown(e) {
            this.cameraTrans.localRotation.getYawPitchRoll(this.yawPitchRoll);
            this.lastMouseX = Laya.stage.mouseX;
            this.lastMouseY = Laya.stage.mouseY;
            this.isMouseDown = true;
        }
        mouseUp(e) {
            this.isMouseDown = false;
        }
        mouseOut(e) {
            this.isMouseDown = false;
        }
        moveForward(distance) {
            this._tempVector3.x = this._tempVector3.y = 0;
            this._tempVector3.z = distance;
            this.cameraTrans.translate(this._tempVector3);
        }
        moveRight(distance) {
            this._tempVector3.y = this._tempVector3.z = 0;
            this._tempVector3.x = distance;
            this.cameraTrans.translate(this._tempVector3);
        }
        moveVertical(distance) {
            this._tempVector3.x = this._tempVector3.z = 0;
            this._tempVector3.y = distance;
            this.cameraTrans.translate(this._tempVector3, false);
        }
    }

    class CameraTouchScript extends CameraCtrBase {
        constructor() {
            super();
            this.distance = 0.0;
            this._tempVector3 = new Laya.Vector3();
            this.lastPosition = new Laya.Vector2(0, 0);
            this.distance = 0.0;
            this.disVector1 = new Laya.Vector2(0, 0);
            this.disVector2 = new Laya.Vector2(0, 0);
            this.isTwoTouch = false;
            this.first = true;
            this.twoFirst = true;
        }
        onStart() {
            super.onStart();
        }
        onUpdate() {
            var touchCount = this._scene.input.touchCount();
            if (1 === touchCount) {
                if (this.isTwoTouch) {
                    return;
                }
                var touch = this._scene.input.getTouch(0);
                if (this.first) {
                    this.lastPosition.x = touch.position.x;
                    this.lastPosition.y = touch.position.y;
                    this.first = false;
                }
                else {
                    var deltaY = touch.position.y - this.lastPosition.y;
                    var deltaX = touch.position.x - this.lastPosition.x;
                    this.lastPosition.x = touch.position.x;
                    this.lastPosition.y = touch.position.y;
                    this.cameraTrans.rotate(new Laya.Vector3(1 * deltaY / 20, 1 * deltaX / 20, 0), true, false);
                }
            }
            else if (0 === touchCount) {
                this.first = true;
                this.twoFirst = true;
                this.lastPosition.x = 0;
                this.lastPosition.y = 0;
                this.isTwoTouch = false;
            }
        }
    }

    class DataCache {
        static get Instance() {
            if (DataCache.instance == null)
                DataCache.instance = new DataCache();
            return DataCache.instance;
        }
    }
    DataCache.instance = null;

    class HttpRequest extends Laya.HttpRequest {
        constructor(caller) {
            super();
            this.caller = null;
            this.completeHandler = null;
            this.errorHandler = null;
            this.progressHandler = null;
            this.caller = caller;
        }
        get timeout() { return this.http.timeout; }
        set timeout(timeout) { this.http.timeout = timeout; }
        send(url, data = null, method = "get", responseType = "text", headers = null) {
            this.once(Laya.Event.COMPLETE, this, this.RequestComplete);
            this.once(Laya.Event.ERROR, this, this.RequestError);
            this.on(Laya.Event.PROGRESS, this, this.RequestProgress);
            super.send(url, data, method, responseType, headers);
        }
        RequestComplete(data) {
            this.off(Laya.Event.PROGRESS, this, this.RequestProgress);
            if (this.completeHandler != null)
                this.completeHandler.call(this, this.caller, data);
        }
        RequestError(data) {
            this.off(Laya.Event.PROGRESS, this, this.RequestProgress);
            if (this.errorHandler != null)
                this.errorHandler.call(this, this.caller, data);
        }
        RequestProgress(data) {
            if (this.progressHandler != null)
                this.progressHandler.call(this, this.caller, data);
        }
    }

    class Layer {
    }
    Layer.Robot = 1;

    class Mathf {
        static Sin(t) {
            return Math.sin(t);
        }
        static Abs(v) {
            return Math.abs(v);
        }
        static Cos(x) {
            return Math.cos(x);
        }
        static LerpAngle(a, b, t) {
            var num = Mathf.Repeat(b - a, 360.0);
            if (num > 180.0)
                num -= 360.0;
            return a + num * Mathf.Clamp01(t);
        }
        static Repeat(t, length) {
            return t - Mathf.Floor(t / length) * length;
        }
        static Floor(f) {
            return Math.floor(f);
        }
        static Clamp01(value) {
            if (value < 0.0)
                return 0.0;
            if (value > 1.0)
                return 1.0;
            return value;
        }
        static Acos(value) {
            return Math.acos(value);
        }
        static Atan2(x, y) {
            return Math.atan2(x, y);
        }
        static Lerp(a, b, t) {
            return a + (b - a) * Mathf.Clamp01(t);
        }
        static InverseLerp(a, b, value) {
            if (a != b)
                return Mathf.Clamp01((value - a) / (b - a));
            else
                return 0.0;
        }
        static Max(a, b) {
            return a > b ? a : b;
        }
        static Min(a, b) {
            return a < b ? a : b;
        }
        static Clamp(value, min, max) {
            if (value < min)
                value = min;
            else if (value > max)
                value = max;
            return value;
        }
    }
    Mathf.Deg2Rad = 0.0174532924;
    Mathf.Rad2Deg = 57.29578;
    Mathf.PI = 3.14159274;

    class SceneManager {
        static LoadScene(url, callder, callbackFunc) {
            Laya.Scene3D.load(url, Laya.Handler.create(SceneManager, SceneManager.OnLoadLevelok, [url, callder, callbackFunc]));
        }
        static LoadSceneByName(name, callder, callbackFunc) {
            let url = 'res3d/LayaScene_' + name + '/Conventional/' + name + '.ls';
            Laya.Scene3D.load(url, Laya.Handler.create(SceneManager, SceneManager.OnLoadLevelok, [url, callder, callbackFunc]));
        }
        static OnLoadLevelok(url, callder, callback, scene) {
            callback.call(callder, scene);
        }
    }

    class Time extends Laya.Script {
    }
    Time.fixedDeltaTime = 0;
    Time.deltaTime = 0;
    Time.time = 0;
    Time.deltaTimeMin = 9999999999999999;
    Time.deltaTimeMax = 0;
    Time.deltaTimeEvr = 0;

    class BaseView extends Laya.Scene {
        constructor() {
            super();
        }
        onAwake() {
            this.width = Laya.stage.width;
            this.height = Laya.stage.height;
        }
    }

    class LoadingViewArg {
        constructor() {
            this.viewName = '';
        }
    }
    class LoadingView extends BaseView {
        static get Instance() {
            return LoadingView.mInstance;
        }
        onAwake() {
            super.onAwake();
            LoadingView.mInstance = this;
        }
        onOpened() {
            Debug.log("播放Loading动画");
            this.loadingAnim.play(0, true);
            Laya.Resource.destroyUnusedResources();
        }
        OnLoadAtlas() {
        }
        onClosed() {
            Debug.log("关闭Loading");
            LoadingView.mInstance = null;
            super.onClosed();
            this.destroy(true);
        }
        startLoad(loadArg) {
            this.arg = loadArg;
            if (loadArg.viewName != null && loadArg.viewName.length > 0) {
                Laya.Scene.open(loadArg.viewName, false, Laya.Handler.create(loadArg.caller, view => {
                    loadArg.loadBack.call(view);
                }));
            }
            else {
                loadArg.loadBack.call(this.arg.caller);
            }
        }
    }

    class ViewManager {
        static get Instance() {
            if (ViewManager.mInstance == null)
                ViewManager.mInstance = new ViewManager();
            return ViewManager.mInstance;
        }
        OpenFullLoading(caller, loadArg) {
            if (LoadingView.Instance != null) {
                LoadingView.Instance.startLoad(loadArg);
            }
            else {
                Laya.Scene.open("scene/Loading.scene", false, Laya.Handler.create(caller, (loadingView) => {
                    loadingView.startLoad(loadArg);
                }));
            }
        }
        CloseFullLoading() {
            if (LoadingView.Instance != null) {
                LoadingView.Instance.close();
            }
        }
    }

    class CloudHallManager extends Laya.Script {
        constructor() {
            super(...arguments);
            this.PosPath = [];
            this.mainScreen = null;
            this.viewStatus = 0;
            this.point = new Laya.Vector2();
            this._outHitResult = new Laya.HitResult();
            this.moveSpeed = 20;
            this.autoMoveSpeed = 2;
            this.cameraCtr = null;
            this.posIndex = 0;
            this.camCtrActive = false;
            this.textureIndex = 0;
        }
        static get Instance() {
            return CloudHallManager.mInstace;
        }
        get CamCtrActive() { return this.camCtrActive; }
        set CamCtrActive(active) {
            this.camCtrActive = active;
            if (this.viewStatus == 1)
                return;
            this.setCameraActive(active);
        }
        setCameraActive(active) {
            if (active) {
                if (this.cameraCtr != null)
                    return;
                if (Laya.Browser.onMobile) {
                    this.cameraCtr = this.camera.addComponent(CameraTouchScript);
                }
                else {
                    this.cameraCtr = this.camera.addComponent(CameraMoveScript);
                }
            }
            else {
                if (this.cameraCtr == null)
                    return;
                this.cameraCtr.destroy();
                this.cameraCtr = null;
            }
        }
        onAwake() {
            CloudHallManager.mInstace = this;
            this.scene = SceneManager.mainScene;
            Laya.Material.load("res3d/LayaScene_CloudHall/Conventional/Assets/Sky.lmat", Laya.Handler.create(this, function (mat) {
                var skyRenderer = this.scene.skyRenderer;
                skyRenderer.mesh = Laya.SkyBox.instance;
                skyRenderer.material = mat;
            }));
            this.camera = this.scene.getChildByName("Main Camera");
            this.robot = this.scene.getChildByName("Robot");
            this.robot.layer = Layer.Robot;
            var cameraPos = this.scene.getChildByName("CameraPos");
            this.PosDigital = cameraPos.getChildByName("PosDigital");
            this.PosCloud = cameraPos.getChildByName("PosCloud");
            this.PosRetail = cameraPos.getChildByName("PosRetail");
            this.PosPartner = cameraPos.getChildByName("PosPartner");
            this.PosSolution = cameraPos.getChildByName("PosSolution");
            var Center = this.scene.getChildByName("Center");
            this.mainScreen = Center.getChildByName("MainScreen");
            var cameraPath = this.scene.getChildByName("CameraPath");
            var count = cameraPath.numChildren;
            for (var i = 0; i < count; i++) {
                var pos = cameraPath.getChildAt(i);
                if (i == 0)
                    this.PosStart = pos;
                this.PosPath.push(pos);
            }
            this._ray = new Laya.Ray(new Laya.Vector3(0, 0, 0), new Laya.Vector3(0, 0, 0));
            this.RequestHallData();
            this.TestMainScreen();
        }
        onStageClick() {
            this.checkClickRobot();
        }
        onUpdate() {
            switch (this.viewStatus) {
                case 0:
                    break;
                case 2:
                    break;
                case 3:
                    this.curMoveDuration += Time.deltaTime;
                    if (this.curMoveDuration >= this.moveDuration) {
                        this.moveDuration = this.moveDuration;
                        this.CheckNextMovePoint();
                    }
                    var pos = new Laya.Vector3();
                    var rate = this.curMoveDuration / this.moveDuration;
                    Laya.Vector3.lerp(this.startPos, this.targetPos.position, rate, pos);
                    this.camera.transform.position = pos;
                    var targetEuler = this.targetPos.rotationEuler;
                    targetEuler.y = Mathf.Repeat(targetEuler.y, 360);
                    var rot = new Laya.Quaternion();
                    Laya.Quaternion.lerp(this.startRot, this.targetPos.rotation, rate, rot);
                    this.camera.transform.rotation = rot;
                    break;
                case 1:
                    this.curMoveDuration += Time.deltaTime;
                    if (this.curMoveDuration >= this.moveDuration) {
                        this.moveDuration = this.moveDuration;
                        this.viewStatus = 2;
                        this.setCameraActive(this.CamCtrActive);
                    }
                    var pos = new Laya.Vector3();
                    var rate = this.curMoveDuration / this.moveDuration;
                    Laya.Vector3.lerp(this.startPos, this.targetPos.position, rate, pos);
                    this.camera.transform.position = pos;
                    var rot = new Laya.Quaternion();
                    Laya.Quaternion.lerp(this.startRot, this.targetPos.rotation, rate, rot);
                    this.camera.transform.rotation = rot;
                    break;
            }
        }
        checkClickRobot() {
            if (this.viewStatus != 0)
                return;
            this.point.x = Laya.MouseManager.instance.mouseX;
            this.point.y = Laya.MouseManager.instance.mouseY;
            this.camera.viewportPointToRay(this.point, this._ray);
            this.scene.physicsSimulation.rayCast(this._ray, this._outHitResult);
            if (this._outHitResult.succeeded) {
                var collider = this._outHitResult.collider.owner;
                if (collider == null || collider.layer != Layer.Robot)
                    return;
                MenuView.Instance.ShowRobotMenu(true);
            }
        }
        EnterTargetView(pos) {
            this.viewStatus = 1;
            this.targetPos = pos.transform;
            var posTemp = this.camera.transform.position;
            this.startPos = new Laya.Vector3(posTemp.x, posTemp.y, posTemp.z);
            posTemp = this.camera.transform.rotationEuler;
            var rotTemp = this.camera.transform.rotation;
            this.startRot = new Laya.Quaternion(rotTemp.x, rotTemp.y, rotTemp.z, rotTemp.w);
            var length = Laya.Vector3.distance(this.targetPos.position, this.startPos);
            this.moveDuration = length / this.moveSpeed;
            this.curMoveDuration = 0;
            this.setCameraActive(false);
            MenuView.Instance.HideRobotMenu();
        }
        EnterMenuView() {
            if (this.viewStatus == 0)
                return;
            this.viewStatus = 0;
            this.camera.transform.position = this.PosStart.transform.position;
            this.camera.transform.rotation = this.PosStart.transform.rotation;
            MenuView.Instance.ShowRobotMenu(false);
        }
        EnterAutoMoveView() {
            if (this.viewStatus == 3)
                return;
            MenuView.Instance.HideRobotMenu();
            this.camera.transform.position = this.PosStart.transform.position;
            this.camera.transform.rotation = this.PosStart.transform.rotation;
            this.viewStatus = 3;
            this.posIndex = 0;
            this.CheckNextMovePoint();
        }
        CheckNextMovePoint() {
            this.posIndex++;
            this.posIndex = this.posIndex % this.PosPath.length;
            this.targetPos = this.PosPath[this.posIndex].transform;
            var posTemp = this.camera.transform.position;
            this.startPos = new Laya.Vector3(posTemp.x, posTemp.y, posTemp.z);
            var rotTemp = this.camera.transform.rotation;
            this.startRot = new Laya.Quaternion(rotTemp.x, rotTemp.y, rotTemp.z, rotTemp.w);
            var length = Laya.Vector3.distance(this.targetPos.position, this.startPos);
            this.moveDuration = length / this.autoMoveSpeed;
            this.curMoveDuration = 0;
        }
        RequestHallData() {
            var request = new HttpRequest(this);
            request.timeout = 5000;
            request.completeHandler = (_caller, data) => {
                Debug.log("请求完成->" + data);
                try {
                    let hallData = JSON.parse(data);
                    DataCache.Instance.HallData = hallData;
                    hallData.data.forEach(this.LoadTexture);
                    MenuView.Instance.ShowWelcome();
                    ViewManager.Instance.CloseFullLoading();
                }
                catch (error) {
                    alert("请求出现异常:" + data);
                }
            };
            request.errorHandler = (_caller, data) => {
                Debug.log("请求错误->" + data);
                alert("请求出现异常:" + data);
            };
            request.progressHandler = (_caller, data) => {
                Debug.log("请求进度->" + data);
            };
            request.send(DataCache.Instance.Config.httpUrl, "", "get", "text/json");
        }
        LoadTexture(data) {
        }
        TestMainScreen() {
            var url = "https://yf.chinaygj.com:18088/uploads/20210312/385e411c937fa317dd1e52b9594e91bb.jpg";
            var texture2D = new Laya.Texture2D();
            Laya.Texture2D.load(url, Laya.Handler.create(this, texture => {
                var unlitMaterial = this.mainScreen.meshRenderer.material;
                unlitMaterial.albedoTexture = texture;
            }));
        }
    }

    class MenuView extends BaseView {
        constructor() {
            super(...arguments);
            this.msg = "Hello! 欢迎来到雷音集团展厅，我是引导机器人小雷，很高兴带您参观，请点击我查看导航菜单！";
            this.tween = null;
            this.interval = 0.2;
            this.msgLength = this.msg.length;
            this.curIndex = 0;
            this._outPos = new Laya.Vector4();
        }
        static get Instance() {
            return MenuView.mInstance;
        }
        onAwake() {
            super.onAwake();
            MenuView.mInstance = this;
            this.btnLein.clickHandler = Laya.Handler.create(this, this.onClickLein, null, false);
            this.btnDigital.clickHandler = Laya.Handler.create(this, this.onClickDigital, null, false);
            this.btnCloud.clickHandler = Laya.Handler.create(this, this.onClickCloud, null, false);
            this.btnRetail.clickHandler = Laya.Handler.create(this, this.onClickRetail, null, false);
            this.btnPartner.clickHandler = Laya.Handler.create(this, this.onClickPartner, null, false);
            this.btnSolution.clickHandler = Laya.Handler.create(this, this.onClickSolution, null, false);
            this.togFreeView.clickHandler = Laya.Handler.create(this, this.onClickTogFreeView, null, false);
            this.btnMenu.clickHandler = Laya.Handler.create(this, this.onClickMenu, null, false);
            this.btnAutoMove.clickHandler = Laya.Handler.create(this, this.onClickAutoMove, null, false);
            this.RobotMenu.visible = false;
        }
        onOpened(data) {
            Laya.timer.frameLoop(1, this, this.loopUpdate);
        }
        onEnable() {
            Debug.log("onEnable MenuView");
        }
        onDisable() {
            Debug.log("onDisable MenuView");
        }
        onClosed() {
            Laya.timer.clear(this, this.UpdateWelcomeInfo);
            Laya.timer.clear(this, this.loopUpdate);
            MenuView.mInstance = null;
            super.onClosed();
            this.destroy(true);
            Laya.Resource.destroyUnusedResources();
        }
        loopUpdate() {
            if (CloudHallManager.Instance == null || CloudHallManager.Instance.camera == null)
                return;
            var camera = CloudHallManager.Instance.camera;
            var robot = CloudHallManager.Instance.robot;
            let rotPos = robot.transform.position;
            camera.viewport.project(rotPos, camera.projectionViewMatrix, this._outPos);
            if (this._outPos.w < 0) {
                return;
            }
            var posX = this._outPos.x / Laya.stage.clientScaleX;
            var posY = this._outPos.y / Laya.stage.clientScaleY;
            this.RobotMenu.pos(posX, posY);
            this.RobotWelcome.pos(posX, posY);
        }
        UpdateWelcomeInfo() {
            if (this.curIndex > this.msgLength)
                return;
            this.tInfo.text = this.msg.substring(0, this.curIndex);
            this.curIndex++;
        }
        onClickLein() {
            Debug.log("点击雷音");
            Laya.stage.bgColor = "#FFFFFF";
            Laya.stage.alignH = Laya.Stage.ALIGN_CENTER;
            Laya.stage.alignV = Laya.Stage.ALIGN_MIDDLE;
            var reference = new Laya.Sprite();
            Laya.stage.addChild(reference);
            var width = Laya.Browser.width;
            var height = Laya.Browser.height;
            Debug.log(width + "==" + height);
            reference.pos(0, 0);
            reference.size(width, height);
            reference.graphics.drawRect(0, 0, reference.width, reference.height, "#000000");
            reference.hitTestPrior = true;
            var videoElement = Laya.Browser.createElement("video");
            Laya.Browser.document.body.appendChild(videoElement);
            videoElement.style.zIndex = Laya.Render.canvas.zIndex + 3;
            videoElement.src = "https://yf.chinaygj.com:18088/uploads/20210519/988f0d5701a1c79aaad44f601908c5eb.mp4";
            videoElement.controls = true;
            videoElement.setAttribute("webkit-playsinline", true);
            videoElement.setAttribute("playsinline", true);
            var btnClose = new Laya.Text();
            reference.addChild(btnClose);
            btnClose.text = "X";
            btnClose.fontSize = 30;
            btnClose.color = "#FFFFFF";
            btnClose.pos(width - 20, 0);
            btnClose.on(Laya.Event.CLICK, this, () => {
                Debug.log("关闭视频");
                Laya.Browser.removeElement(videoElement);
                reference.destroy(true);
            });
            Laya.stage.on(Laya.Event.RESIZE, this, Laya.Utils.fitDOMElementInArea, [videoElement, reference, 0, 30, reference.width, reference.height - 30]);
        }
        onClickDigital() {
            Debug.log("点击数字孪生");
            CloudHallManager.Instance.EnterTargetView(CloudHallManager.Instance.PosDigital);
        }
        onClickCloud() {
            Debug.log("点击云计算");
            CloudHallManager.Instance.EnterTargetView(CloudHallManager.Instance.PosCloud);
        }
        onClickRetail() {
            Debug.log("点击零售");
            CloudHallManager.Instance.EnterTargetView(CloudHallManager.Instance.PosRetail);
        }
        onClickPartner() {
            Debug.log("点击资质和伙伴");
            CloudHallManager.Instance.EnterTargetView(CloudHallManager.Instance.PosPartner);
        }
        onClickSolution() {
            Debug.log("点击解决方案");
            CloudHallManager.Instance.EnterTargetView(CloudHallManager.Instance.PosSolution);
        }
        onClickTogFreeView() {
            Debug.log("自由视角开关->" + this.togFreeView.selected);
            CloudHallManager.Instance.CamCtrActive = this.togFreeView.selected;
        }
        onClickMenu() {
            Debug.log("点击主菜单");
            CloudHallManager.Instance.EnterMenuView();
        }
        onClickAutoMove() {
            Debug.log("点击自动漫游");
            CloudHallManager.Instance.EnterAutoMoveView();
        }
        ShowRobotMenu(anim) {
            if (this.RobotMenu.visible)
                return;
            if (anim)
                this.maskAnim.play(0, false);
            this.RobotMenu.visible = true;
            this.HideWelcome();
        }
        HideRobotMenu() {
            this.RobotMenu.visible = false;
        }
        ShowWelcome() {
            this.RobotMenu.visible = false;
            this.RobotWelcome.visible = true;
            this.ButtonsView.visible = false;
            this.tInfo.text = '';
            this.curIndex = 0;
            Laya.timer.loop(100, this, this.UpdateWelcomeInfo);
        }
        HideWelcome() {
            if (!this.RobotWelcome.visible)
                return;
            this.RobotWelcome.visible = false;
            this.ButtonsView.visible = true;
            Laya.timer.clear(this, this.UpdateWelcomeInfo);
        }
    }

    class ChangeSceneManager {
        static OnSceneLoaded(scene) {
            Laya.stage.addChildAt(scene, 0);
            SceneManager.mainScene = scene;
            Debug.log("3D场景加载完成->" + scene);
            scene.addComponent(CloudHallManager);
        }
        static GotoHall(callBack) {
            var loadArg = new LoadingViewArg();
            loadArg.caller = this;
            loadArg.viewName = "scene/HallMenu.scene";
            loadArg.loadBack = view => {
                SceneManager.LoadSceneByName("CloudHall", this, this.OnSceneLoaded);
                if (callBack != null) {
                    callBack.call(null);
                }
            };
            ViewManager.Instance.OpenFullLoading(this, loadArg);
        }
    }

    class InitView extends BaseView {
        onAwake() {
            super.onAwake();
            var loadArg = new LoadingViewArg();
            loadArg.caller = this;
            loadArg.loadBack = view => {
                Laya.loader.load("GlobalConfig.config", Laya.Handler.create(this, this.loadConfigSuccess));
            };
            ViewManager.Instance.OpenFullLoading(this, loadArg);
        }
        loadConfigSuccess(data) {
            Debug.log("加载全局配置");
            var config = JSON.parse(data);
            DataCache.Instance.Config = config;
            ChangeSceneManager.GotoHall(() => {
                this.close();
            });
        }
        onClosed() {
            super.onClosed();
            this.destroy(true);
            Laya.Resource.destroyUnusedResources();
        }
    }

    class GameConfig {
        constructor() {
        }
        static init() {
            var reg = Laya.ClassUtils.regClass;
            reg("script/Views/MenuView.ts", MenuView);
            reg("script/Views/InitView.ts", InitView);
            reg("script/Views/LoadingView.ts", LoadingView);
        }
    }
    GameConfig.width = 1920;
    GameConfig.height = 1080;
    GameConfig.scaleMode = "full";
    GameConfig.screenMode = "horizontal";
    GameConfig.alignV = "top";
    GameConfig.alignH = "left";
    GameConfig.startScene = "scene/Init.scene";
    GameConfig.sceneRoot = "";
    GameConfig.debug = false;
    GameConfig.stat = false;
    GameConfig.physicsDebug = false;
    GameConfig.exportSceneToJson = true;
    GameConfig.init();

    class Input extends Laya.Script {
        constructor() {
            super();
            this.count = 0;
            this.counttime = 0;
            this.preMouseX = 0;
            this.firstX = -12345678;
            this.seconx = 0;
            this.mouseDown_y = 0;
            this.mouseDown_y_Time = 0;
            this.slide_mouseDown_x = 0;
        }
        onAwake() {
            Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.p_onMouseDown);
            Laya.stage.on(Laya.Event.MOUSE_UP, this, this.p_onMouseUp);
            Laya.stage.on(Laya.Event.KEY_DOWN, this, this.onKeyDownEvent);
            Laya.stage.on(Laya.Event.KEY_UP, this, this.onKeyUpEvent);
            this.preMouseX = Laya.MouseManager.instance.mouseX;
        }
        onKeyDownEvent(e) {
            Input.dicKeyDown[e.keyCode] = true;
            Input.dicKeyUpdate[e.keyCode] = true;
        }
        onKeyUpEvent(e) {
            Input.dicKeyDown[e.keyCode] = false;
            Input.dicKeyUpdate[e.keyCode] = false;
        }
        p_onMouseDown() {
            Input.mouseButton0down = true;
            Input.mouseButton0Up = false;
            Input.mouseButton0DwonHold = true;
        }
        p_onMouseUp() {
            Input.mouseButton0Up = true;
            Input.mouseButton0down = false;
            Input.mouseButton0DwonHold = false;
        }
        onLateUpdate() {
            Input.mouseButton0down = false;
            Input.mouseButton0Up = false;
            Input.GetAxisRaw_Mouse_X = 0;
            Input.slideUp = false;
            Input.slideLeft = false;
            Input.slideRight = false;
            if (Laya.Browser.onPC) {
                for (let k in Input.dicKeyDown) {
                    Input.dicKeyDown[k] = false;
                }
                for (let k in Input.dicKeyUpdate) {
                    Input.dicKeyUpdate[k] = false;
                }
            }
        }
        onUpdate() {
            this.onUpdate_mouse();
        }
        static GetKeyDown(e) {
            if (Laya.Browser.onPC == false)
                return false;
            return Input.dicKeyDown[e];
        }
        static GetKey(e) {
            if (Laya.Browser.onPC == false)
                return false;
            if (Input.dicKeyUpdate[e] == null)
                return false;
            return Input.dicKeyUpdate[e];
        }
        onUpdate_mouse() {
            if (Input.mouseButton0DwonHold) {
                if (this.firstX == -12345678) {
                    this.firstX = Laya.stage.mouseX;
                }
                else {
                    this.seconx = Laya.stage.mouseX;
                    var movementX = this.seconx - this.firstX;
                    this.firstX = this.seconx;
                    Input.GetAxisRaw_Mouse_X = movementX;
                }
            }
            if (Input.mouseButton0Up) {
                Input.GetAxisRaw_Mouse_X = 0;
                this.firstX = -12345678;
                ;
                this.seconx = 0;
            }
            if (Input.mouseButton0down) {
                this.mouseDown_y = Laya.MouseManager.instance.mouseY;
                this.mouseDown_y_Time = Time.time;
                this.slide_mouseDown_x = Laya.MouseManager.instance.mouseX;
            }
            if (Input.mouseButton0Up) {
                let mouse_up_y = Laya.MouseManager.instance.mouseY;
                let mouse_up_x = Laya.MouseManager.instance.mouseX;
                let mouse_up_y_time = Time.time;
                let OpTime = mouse_up_y_time - this.mouseDown_y_Time < 0.3;
                if (OpTime) {
                    if (this.mouseDown_y - mouse_up_y > 100) {
                        Input.slideUp = true;
                        Debug.log('slideUp');
                    }
                    if (this.slide_mouseDown_x - mouse_up_x > 100) {
                        Input.slideLeft = true;
                        Debug.log('slide left');
                    }
                    else if (mouse_up_x - this.slide_mouseDown_x > 100) {
                        Debug.log('slide right');
                        Input.slideRight = true;
                    }
                }
            }
        }
    }
    Input.mouseButton0down = false;
    Input.mouseButton0Up = false;
    Input.mouseButton0DwonHold = false;
    Input.dicKeyDown = {};
    Input.dicKeyUpdate = {};
    Input.GetAxisRaw_Mouse_X = 0;
    Input.slideUp = false;
    Input.slideLeft = false;
    Input.slideRight = false;

    class UnityEnagine extends Laya.Script {
        constructor() {
            super(...arguments);
            this.logFps = false;
            this.openAppTimeSc = 0;
            this.fpsTime = 0;
            this.framCount = 0;
            this.fps = 0;
            this.fpsmin = 9999;
            this.fpsMax = 0;
        }
        onAwake() {
            this.owner.addComponent(Input);
            this.openAppTimeSc = Laya.timer.currTimer * 0.001;
        }
        onUpdate() {
            Time.fixedDeltaTime = Laya.timer.delta;
            Time.deltaTime = Laya.timer.delta * 0.001;
            if (this.logFps)
                this.calFps();
            Time.time = Laya.timer.currTimer * 0.001 - this.openAppTimeSc;
        }
        calFps() {
            this.framCount += 1;
            this.fpsTime += Time.deltaTime;
            if (this.fpsTime > 1) {
                this.fps = this.framCount;
                this.fpsTime = 0;
                this.framCount = 0;
                this.fpsMax += this.fps;
                if (this.fps < this.fpsmin)
                    this.fpsmin = this.fps;
                Debug.log('fps 当前=', this.fps, '最小=', this.fpsmin, '总帧数', this.fpsMax);
            }
        }
    }

    class Main {
        constructor() {
            if (window["Laya3D"])
                Laya3D.init(GameConfig.width, GameConfig.height);
            else
                Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
            Laya["Physics"] && Laya["Physics"].enable();
            Laya["DebugPanel"] && Laya["DebugPanel"].enable();
            Laya.stage.scaleMode = GameConfig.scaleMode;
            Laya.stage.screenMode = GameConfig.screenMode;
            Laya.stage.alignV = GameConfig.alignV;
            Laya.stage.alignH = GameConfig.alignH;
            Config.useRetinalCanvas = true;
            Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;
            if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true")
                Laya.enableDebugPanel();
            if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"])
                Laya["PhysicsDebugDraw"].enable();
            if (GameConfig.stat)
                Laya.Stat.show();
            Laya.alertGlobalError(true);
            Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
        }
        onVersionLoaded() {
            Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
        }
        onConfigLoaded() {
            let node = new Laya.Node();
            node.name = "ManagerNode";
            Laya.stage.addChild(node);
            node.addComponent(UnityEnagine);
            Laya.SoundManager.autoReleaseSound = false;
            GameConfig.startScene && Laya.Scene.open(GameConfig.startScene);
        }
    }
    new Main();

}());
